package com.lxq.test2112.main03;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    //大写:A  小写:a  数字:0
    public static char getCharType(char c){
        char type = '!';
        if ('A'<=c && c<='Z'){
            type = 'A';
        }
        if ('a'<=c && c<='z'){
            type = 'a';
        }
        if ('0'<=c && c<='9'){
            type = '0';
        }
        return type;
    }

    public static ArrayList<Integer> getUsefulData(ArrayList<Integer> UsefulData,String data){
        char prev = getCharType(data.charAt(0));
        for (int i=0 ; i<data.length() ; i++){
            char c = data.charAt(i);
            char flag = getCharType(c);
            if (flag == prev){
                //undo
            }
            if ((prev == 'A' || prev == '0') && flag == 'a') {
                UsefulData.add(27);
            }
            if ((prev == 'A' && flag == '0') || (prev == 'a' && flag == '0') || (prev == '0' && flag == 'A')){
                UsefulData.add(28);
            }
            if ((prev == 'a' && flag == 'A')){
                UsefulData.add(28);
                UsefulData.add(28);
            }
            UsefulData.add(c-flag);
            prev = flag;

        }
        if (UsefulData.size()%2 != 0){
            UsefulData.add(29);
        }
        return UsefulData;
    }


    public static ArrayList<Integer> getDataCode(ArrayList<Integer> dataCode,int arrayNum,String data,int testLevel){
        int unUsefulDataNum = 0,testNum = 0;
        ArrayList<Integer> UsefulData = new ArrayList<Integer>();
        getUsefulData(UsefulData,data);

        if (testLevel != -1) {
            testNum = (int) Math.pow(2,testLevel+1);
        }
        unUsefulDataNum = (1+UsefulData.size()/2+testNum)%arrayNum==0?0:arrayNum - (1+UsefulData.size()/2+testNum)%arrayNum;

        //添加长度码字
        dataCode.set(0,1+UsefulData.size()/2+unUsefulDataNum);
        //添加有效码字
        for (int i=0;i<UsefulData.size();i+=2){
            dataCode.add(UsefulData.get(i)*30+UsefulData.get(i+1));
        }
        //添加无效码字
        for (int i=0 ; i<unUsefulDataNum ; i++){
            dataCode.add(900);
        }
        //添加校验码字
        //TODO:编写校验码字


        return dataCode;
    }


    public static void main(String[] args) {
        //输入
        //字符串长度，校验等级，校验码数
        int arrayNum,testLevel;
        //待编码数据
        String data = null;
        //数据区码字
        ArrayList<Integer> dataCode = new ArrayList<Integer>();
        dataCode.add(0,0);

        Scanner sc = new Scanner(System.in);
        arrayNum = sc.nextInt();
        testLevel = sc.nextInt();
        data = sc.next();


        getDataCode(dataCode,arrayNum,data,testLevel);
//        System.out.println(dataCode);
        for (Integer i:dataCode
             ) {
            System.out.println(i);
        }

        //输出
    }
}
